package demo_Book;

import java.util.Scanner;

public class View {

    private Server server;
    private  Scanner scanner;
    public View( ) {
        server = new Server();
        scanner = new Scanner(System.in);
    }
    public  void scan() {
        System.out.println("欢迎使用管理系统");
        System.out.println("请选择用户类型：");
        System.out.println("1. 用户");
        System.out.println("2. 管理员");
        System.out.println("0. 退出系统");
        System.out.println("请选项：");
    }
    public void run() {
        while (true) {
            scan();
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    //用户界面
                    userMenu();
                break;
                case 2:
                    //管理界面
                    adminMenu();
                    break;
                case 0:
                    System.out.println("感谢使用，再见！");
                    return;
                default:
                    System.out.println("无效输入，请重新输入");
            }
        }
    }

    //usermenu
    public void userMenu() {
        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1. 浏览书店");
            System.out.println("0. 退出书店");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    rowsBooks();
                    break;
                case 0:
                    run();
                    return;
                default:
                    System.out.println("无效的选择，请重新输入。");
            }
        }
    }
    //书籍列表
    public void rowsBooks() {
        System.out.println("所有书籍：");
        server.printAllBooks();
        System.out.println("请选择操作：");
        System.out.println("1. 购买商品");
        System.out.println("0. 返回");
        int choice = scanner.nextInt();
        switch (choice) {
            case 1:
                server.addToCart();
                break;
            case 0:
                return;
            default:
                System.out.println("无效的选择，请重新输入。");
        }
    }
    //admin
    public void adminMenu() {
        while (true) {
            System.out.println("admin!请选择操作：");
            System.out.println("1. 添加书籍信息");
            System.out.println("2. 修改书籍信息");
            System.out.println("3. 删除书籍信息");
            System.out.println("4. 查看书籍信息");
            System.out.println("0. 退出系统");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    server.addBook();
                    break;
                case 2:
                    server.updateBook();
                    break;
                case 3:
                    server.deleteBook();
                    break;
                case 4:
                    server.printAllBooks();
                    break;
                case 0:
                    run();
                    return;
                default:
                    System.out.println("无效的选择，请重新输入。");
            }
        }
    }
}